package cn.edu.xust.health.configuration;


import cn.edu.xust.health.interceptor.TokenInterceptor;
import lombok.extern.java.Log;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Log
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {

    @Bean
    @Scope("singleton")
    public TokenInterceptor getTokenInterceptor() {
        log.info("创建拦截器实例");
        TokenInterceptor t = new TokenInterceptor();
        return t;
    }

    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册拦截器");
        InterceptorRegistration registration = registry.addInterceptor(getTokenInterceptor());
        // 设置拦截路径
        registration.addPathPatterns("/user/**");
        // 设置白名单(即不拦截的路径)
        registration.excludePathPatterns("/user/sign/up", "/user/sign/in");
    }

}
